﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Infrastructure;
using Enterprise.Model.Meeting;
namespace Enterprise.Data.Meeting
{
    /// <summary>
    /// 会议数据操作
    /// </summary>
    public class MeetingData
    {

        /// <summary>
        /// 通知公告内容显示
        /// </summary>
        /// <param name="articleId"></param>
        /// <returns></returns>
        public MeetingEntity MeetingDisp(int meetingId)
        {
            string cmd = "Select * from MEETING_INFO where MEETINGID=" + meetingId;
            IDataReader dr = DbExecute.DataReader(cmd);
            return FormatMeetingList(dr).FirstOrDefault();
        }

        /// <summary>
        ///  会议数据列表
        /// </summary>
        /// <returns></returns>
        public List<MeetingEntity> MeetingList()
        {
            List<MeetingEntity> list = new List<MeetingEntity>();
            string cmd = "Select * from MEETING_INFO";
            IDataReader dr = DbExecute.DataReader(cmd);
            return FormatMeetingList(dr);
        }

        /// <summary>
        /// 数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void MeetingExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }

        /// <summary>
        /// 数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void MeetingExecute(string cmd, string item1, object item1Value, string item2, object item2Value)
        {
            DbExecute.ExecuteCommand(cmd, item1, item1Value, item2, item2Value);
        }

        /// <summary>
        /// 提取通用转换数据代码
        /// 格式化通知公告
        /// </summary>
        /// <param name="dr">数据集</param>
        /// <returns></returns>
        private List<MeetingEntity> FormatMeetingList(IDataReader dr)
        {
            List<MeetingEntity> list = new List<MeetingEntity>();
            while (dr.Read())
            {
                MeetingEntity entity = new MeetingEntity();
                if (!Convert.IsDBNull(dr["MEETINGID"])) entity.MeetingId = Convert.ToInt32(dr["MEETINGID"]);
                if (!Convert.IsDBNull(dr["MDEPARTMENT"])) entity.MDepartMent = Convert.ToInt32(dr["MDEPARTMENT"]);
                if (!Convert.IsDBNull(dr["MUSER"])) entity.MUser = Convert.ToInt32(dr["MUSER"]);
                if (!Convert.IsDBNull(dr["MADDRESS"])) entity.MAddress = Convert.ToString(dr["MADDRESS"]);
                if (!Convert.IsDBNull(dr["MTIME"])) entity.MTime = Convert.ToDateTime(dr["MTIME"]);
                if (!Convert.IsDBNull(dr["MZCR"])) entity.MZcr = Convert.ToString(dr["MZCR"]);
                if (!Convert.IsDBNull(dr["MTITLE"])) entity.MTitle = Convert.ToString(dr["MTITLE"]);
                if (!Convert.IsDBNull(dr["MTITLERU"])) entity.MTitleRu = Convert.ToString(dr["MTITLERU"]);
                if (!Convert.IsDBNull(dr["MCONTENT"])) entity.MContent = Convert.ToString(dr["MCONTENT"]);
                if (!Convert.IsDBNull(dr["MCONTENTRU"])) entity.MContentRu = Convert.ToString(dr["MCONTENTRU"]);
                if (!Convert.IsDBNull(dr["MFILES"])) entity.MFiles = Convert.ToString(dr["MFILES"]);
                if (!Convert.IsDBNull(dr["MUSERS"])) entity.MUsers = Convert.ToString(dr["MUSERS"]);
                if (!Convert.IsDBNull(dr["MUSERID"])) entity.MUserId = Convert.ToInt32(dr["MUSERID"]);
                if (!Convert.IsDBNull(dr["MCREATETIME"])) entity.MCreateTime = Convert.ToDateTime(dr["MCREATETIME"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

    }
}
